package com.javaxiaobang.es.controller;

import com.javaxiaobang.es.service.EsService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class EsController {

    @RequestMapping("/")
    String home() {
        return "你好 es !";
    }


    @GetMapping(value = "/{index}/_search")
    public String searchDocument(@PathVariable("index") String index,
                                 @RequestParam(value = "q", required = true) String queryStr) {
        EsService searcher = new EsService();
        String result = searcher.query(index, queryStr);
        return result;
    }

}
